#include <iostream>
using std::cout;
using std::endl;

class Test
{};

class Point
{
public:
    Point()
    : _ix(0)
    , _iy(0)
    {}

    Point(int x ,int y)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point &)" << endl;
    }
    
    Point & operator=(const Point & rhs){
        cout << "赋值运算符函数" << endl;
        this->_ix = rhs._ix;
        this->_iy = rhs._iy;
        return *this;
    }

    //this指针的类型Point * const this
    //对象调用成员函数，成员函数执行时
    //编译器会自动加入this指针作为函数的第一个参数
    //不要在参数列表中显式写出this指针
    void print() const{
        //this指针一定指向本对象（此次调用成员函数的对象）
        /* cout << &this << endl; */
        /* this = new Point(1,2); */
        /* this->_ix = 100; */
        cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test1(){
    Point pt1(1,2);
    Point pt2(3,4);
    Point pt3(5,5);
    Point arr[3] = {pt1,pt2,pt3};
    cout << &pt1 << endl;
    cout << arr << endl;

    Point pts[2] = {Point(1, 2), Point(30, 4)};
    (pts + 1)->print();

    Point arr2[3] = {{1,7},{4,5},{7,9}};
    arr2[1].print();
}

void test2(){
    int * p = new int[3]();
    delete [] p;
    p = nullptr;

    Point * pt = new Point[5]();
    pt->print();
    (pt + 1)->print();
    delete [] pt;
    pt = nullptr;
}

void test0(){
    const Point pt1(1,2);
    Point pt2(3,9);

    Point * p1 = nullptr;
    const Point * p2 = &pt1;
    Point * p3 = &pt2;

    Point * p4 = new Point(2,9);
    p4->print();
    (*p4).print();
    delete p4;
    p4 = nullptr;

}

int main(void){
    test2();
    return 0;
}
